package com.zz.controller;


import java.io.IOException;


import com.zz.util.Tesseract_ocrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;


@Controller
public class OcrController {

    @Value("${fileUpLoadPath}")
    private String imgfilePath;

    @Value("${lanpath}")
    private String lanpath;

    private Logger logger = LoggerFactory.getLogger(OcrController.class);


    @RequestMapping("/view")
    public String view(){
        return "view";
    }

    @RequestMapping("/hello")
    public String  hi(){
        return "index";
    }


    @RequestMapping("/ocr")
    @ResponseBody
    public String getocr(MultipartHttpServletRequest multiReq) throws IOException {
        MultipartFile multipartFile= multiReq.getFile("file");
        String filename=multipartFile.getOriginalFilename();
        System.out.println("图片名字："+multipartFile.getOriginalFilename());
//        File sourceFile=new File(filePath+filename);
        String imgFile=imgfilePath+filename;      /*源word文件路径*/
//        multipartFile.transferTo(sourceFile);
        Tesseract_ocrUtil tesseract=new Tesseract_ocrUtil();

        String str=tesseract.getocr(imgFile,lanpath);

        return str;

    }


}